﻿using Microsoft.EntityFrameworkCore;

namespace Devonline.AspNetCore;

/// <summary>
/// 主数据的附加信息类服务
/// 一个业务数据中仅有一个类型为: TAdditional 的附加信息集合
/// </summary>
/// <typeparam name="TDbContext">数据库上下文</typeparam>
/// <typeparam name="TAdditional">附加信息数据类型</typeparam>
/// <typeparam name="TKey">主键类型</typeparam>
public interface IDataAdditionalService<TDbContext, TEntitySet, TAdditional, TKey>
    where TDbContext : DbContext
    where TEntitySet : class, IEntitySet<TKey>
    where TAdditional : class, IAdditional<TKey>
    where TKey : IConvertible
{
    /// <summary>
    /// 新增业务数据的附加信息
    /// </summary>
    /// <param name="entitySet">业务数据</param>
    /// <param name="additionals">附加数据集合</param>
    /// <returns></returns>
    Task AddAdditionalsAsync(TEntitySet entitySet, IEnumerable<TAdditional>? additionals = default);
    /// <summary>
    /// 更新业务数据的附加信息
    /// </summary>
    /// <param name="entitySet">业务数据</param>
    /// <param name="additionals">附加数据集合</param>
    /// <param name="isLogical">是否逻辑操作, 默认不是</param>
    /// <returns></returns>
    Task UpdateAdditionalsAsync(TEntitySet entitySet, IEnumerable<TAdditional>? additionals = default, bool isLogical = false);
    /// <summary>
    /// 删除业务数据的附加信息
    /// </summary>
    /// <param name="id">业务数据主键</param>
    /// <param name="isLogical">是否逻辑操作, 默认不是</param>
    /// <returns></returns>
    Task DeleteAdditionalsAsync(TKey id, bool isLogical = false);
}

/// <summary>
/// 字符串作为主键的主数据的附加信息类服务
/// 一个业务数据中仅有一个类型为: TAdditional 的附加信息集合
/// </summary>
/// <typeparam name="TDbContext">数据库上下文</typeparam>
/// <typeparam name="TAdditional">附加信息数据类型</typeparam>
public interface IDataAdditionalService<TDbContext, TEntitySet, TAdditional> :
    IDataAdditionalService<TDbContext, TEntitySet, TAdditional, string>
    where TDbContext : DbContext
    where TEntitySet : class, IEntitySet<string>
    where TAdditional : class, IAdditional<string>
{ }